<template>
  <div class="main-wrap">
    <div class="wrapper">
      <div class="center-box">
        <el-form ref="user" :model="user">
          <div class="box-hd">
            <span class="tit">用户注册</span>
            <router-link tag="a" to="/login">账号登陆</router-link>
          </div>
          <el-form-item class="txtin-box" label="用户名">
            <el-input  v-model="user.userName"  placeholder="用户名"></el-input>
          </el-form-item>
          <el-form-item class="txtin-box" label="手机">
            <el-input v-model="user.phone"  placeholder="手机"></el-input>
          </el-form-item>
          <el-form-item class="txtin-box" label="密码">
            <el-input v-model="password.password" type="password"  placeholder="密码"></el-input>
          </el-form-item>
          <el-form-item class="txtin-box" label="确认密码">
            <el-input v-model="password.confirmPassword" type="password"  placeholder="确认密码"></el-input>
          </el-form-item>
          <el-button style="background: #ff0000; color: #ffffff" class="tj" type="submit" @click="onSign">注册</el-button>
          <div class="other-way clearfix">
            <a class="item first" href="">
              <img src="img/login/weixin.jpg" alt="" class="ico" />
              <span class="label">微信</span>
            </a>
            <a class="item" href="">
              <img src="img/login/qq.jpg" alt="" class="ico" />
              <span class="label">微信</span>
            </a>
            <a class="item" href="">
              <img src="img/login/sina.jpg" alt="" class="ico" />
              <span class="label">微信</span>
            </a>
          </div>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
import http from '../../../base/api/http'
export default {
  name: 'SignWrap',
  data () {
    return {
      user: {
        userName: '',
        password: '',
        phone: ''
      },
      password: {
        password: '',
        confirmPassword: ''
      }
    }
  },
  methods: {
    onSign () {
      if (this.password.password === this.password.confirmPassword) {
        // TODO 空白校验
        this.user.password = this.password.password
        http.requestPost('/java/api/user/signUser', this.user).then((res) => {
          let code = res.status
          if (code !== 0) {
            alert(res.msg)
            return 0
          }
          alert('注册成功')
          this.$router.push('login')
        })
      } else {
        alert('两次密码不一致')
      }
    }
  }
}
</script>
<style></style>
